<template>
  <div>
    <el-row>
      <el-col :span="24">
        <div class="search-box">
          <el-form :inline="true" size="medium">
          </el-form>

          <el-form :inline="true" size="medium" :model="searchForm">
            <el-form-item>
              <el-button type="primary" @click="search">刷新</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>

    <el-table
      :data="tableData"
      :header-cell-style="{backgroundColor:'#f4f4f5',textAlign:'center'}"
      :cell-style="{textAlign:'center'}"
      :height="tableHeight"
      border
      style="width: 100%">
      <el-table-column
        prop="id"
        label="序号"
        type="index"
        width="80">
      </el-table-column>
      <el-table-column
        prop="carEntName"
        label="车企"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="carTypeName"
        label="车型类别"
        min-width="100">
      </el-table-column>
      <el-table-column
        prop="productTypeName"
        label="申报类型"
        min-width="150">
        <template scope="scope">
          {{scope.row.productTypeName1+"/"+scope.row.productTypeName2}}
        </template>
      </el-table-column>
      <!-- <el-table-column
        prop="testItems"
        label="检测项目"
        min-width="170">
        <template scope="scope">
          <span v-html="parseTestItem2(scope.row)"></span>
        </template>
      </el-table-column> -->
      <el-table-column
        prop="siteName"
        label="场地"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="orgName"
        label="检测机构"
        min-width="120">
      </el-table-column>

      <el-table-column
        prop="currentStep"
        label="当前任务步骤"
        min-width="120">
        <template scope="scope">
          {{getDoneTitles(scope.row.currentStep)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="id"
        label="任务状态"
        min-width="120">
        <template scope="scope">
          <span v-if="scope.row.taskStatus == 1">已完成</span>
          <span v-if="scope.row.taskStatus == 2">进行中</span>
          <span v-if="scope.row.taskStatus == 3">回退(原因:{{scope.row.msg}})</span>
          <span v-if="scope.row.taskStatus == 4">转交</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="currentStepUserName"
        label="当前处理用户"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="historyName"
        label="前一步完成用户"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="suggestTime"
        label="建议完成时间"
        min-width="120">
        <template scope="scope">
          {{fmtDate(scope.row.suggestTime)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="importance"
        label="是否重要车型类别"
        min-width="120">
        <template scope="scope">
          {{significance(scope.row.importance)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="cause"
        label="原因"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="updateTime"
        label="最后修改时间"
        min-width="160">
        <template scope="scope">
          {{fmtDate(scope.row.updateTime)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="note"
        fixed="right"
        label="备注"
        min-width="160">
      </el-table-column>
      <el-table-column
        fixed="right"
        prop="address"
        label="操作"
        min-width="200">
        <template slot-scope="scope">

          <!-- <template v-if="scope.row.currentStep=='a'">
            <el-button size="mini" type="primary" @click="handlePVTask(scope.$index, scope.row)">子任务</el-button>
          </template>
          <el-button size="mini" type="primary" @click="handleTaskDone(scope.$index, scope.row)">处理</el-button>
          <template v-if="scope.row.currentStep!='a'">
            <el-button size="mini" type="primary" @click="handleTaskBack(scope.$index, scope.row)">回退</el-button>
          </template>
          <el-button size="mini" type="primary" @click="handleTaskChangeUser(scope.$index, scope.row)">转交</el-button>
          -->
          <el-button size="mini" type="primary" @click="handleShowTaskItems(scope.$index, scope.row)">查看</el-button>
          <el-button size="mini" type="primary" @click="lookStep(scope.$index, scope.row)">查看步骤</el-button>
          <!-- <el-button size="mini" type="primary" style="margin-top: 8px;" @click="handleBindCar(scope.$index, scope.row)">绑定车辆</el-button> -->

        </template>

      </el-table-column>
    </el-table>
    <div class="block">
       <span class="demonstration"></span>
       <el-pagination
         @size-change="handleSizeChange"
         @current-change="handleCurrentChange"
         :current-page="currentPage"
         :page-sizes="[10, 20, 50, 100,200]"
         :page-size="pageSize"
         layout="total, sizes, prev, pager, next, jumper"
         :total="total">
       </el-pagination>
     </div>

    <el-dialog title="转交" :visible.sync="changeUserFormVisible" width="500px" :close-on-click-modal="false">
      <el-form :model="changeUserForm" ref="changeUserForm" >
        <el-form-item label="用户" label-width="100px">
          <el-select v-model="changeUserForm.userId" placeholder="请选择" style="width: 90%;" >
            <el-option
              v-for="item in userList"
              :key="item.id"
              :label="item.nickname"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="changeUserFormVisible = false">取 消</el-button>
        <el-button type="primary" @click.native.prevent="submitChangeUser">转交</el-button>
      </div>
    </el-dialog>

  <el-dialog title="回退" :visible.sync="backFormVisible" width="500px" :close-on-click-modal="false">
      <el-form :model="backForm" ref="backForm" >
        <el-form-item label="回退步骤" label-width="100px">
          <el-select v-model="backForm.backStep" placeholder="请选择" style="width: 90%;" >
            <el-option
              v-for="item in backStepList"
              :key="item.key"
              :label="item.label"
              :value="item.key">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="原因" label-width="100px">
          <el-input v-model="backForm.msg" placeholder="请输入原因"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="backFormVisible = false">取 消</el-button>
        <el-button type="primary" @click.native.prevent="submitBack">回退</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="getDoneTitle()" :visible.sync="doneFormVisible" width="700px" :close-on-click-modal="false">
      <el-form :model="backForm" ref="backForm" >
        <el-row>
          <el-col :span="24">
            <table class="test-item-table">
              <tr>
                <th>项目代码</th>
                <th>检测项目</th>
                <th>数量</th>
                <th>备注</th>
                <th>是否完成</th>

              </tr>

              <tr v-for="(item,index) in taskItems">
                <td>{{item.serialNumber}}</td>
                <td>{{item.itemName}}</td>
                <td>{{item.num}}</td>
                <td>{{item.itemNote}}</td>
                <td>
                  <input v-model="doneForm.doneTaskItemIds" type="checkbox" disabled="disabled" :value="item.id" />
                </td>
              </tr>

            </table>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" style="margin-top: 20px;">
        <el-button @click="doneFormVisible = false">关 闭</el-button>
        <!-- <el-button type="primary" @click.native.prevent="submitDoneSave">保存</el-button>
        <el-button type="primary" @click.native.prevent="submitDoneNext">{{isLastStep()?"完成":'提交下一步'}}</el-button> -->
      </div>
    </el-dialog>

    <el-dialog title="全部步骤" :visible.sync="doneFormVisibles" width="80%" :close-on-click-modal="false">
        <el-row>
          <el-col :span="24">
            <table class="test-item-table">
              <tr>
                <th>检测方案核定</th>
                <th>参数填报</th>
                <th>方案参数审核</th>
                <th>报告出具</th>
                <th>报告审核</th>
                <th>批准</th>
                <th>原始记录</th>
                <th>提交检测机构</th>
              </tr>

              <tr >
                <td>{{taskLookStep.aName}}</td>
                <td>{{taskLookStep.bName}}</td>
                <td>{{taskLookStep.cName}}</td>
                <td>{{taskLookStep.dName}}</td>
                <td>{{taskLookStep.eName}}</td>
                <td>{{taskLookStep.fName}}</td>
                <td>{{taskLookStep.gName}}</td>
                <td>{{taskLookStep.hName}}</td>
              </tr>
            </table>
          </el-col>
        </el-row>
      <div slot="footer" class="dialog-footer" style="margin-top: 20px;">
        <el-button @click="doneFormVisibles = false">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog title="车辆绑定" :visible.sync="bindCarVisible" width="700px" :close-on-click-modal="false">
      <el-row>
        <el-col :span="24">
          <table class="test-item-table">
            <tr>
              <th>检测项目</th>
              <th>数量</th>
              <th>车辆</th>
            </tr>

            <tr v-for="(item,index) in taskItemsAll" :key="item.id">
              <td>{{item.itemName}}</td>
              <td>{{item.num}}</td>
              <td>
                <el-select v-model="item.carIds" placeholder="请选择" size="mini"
                    :multiple="true"
                    :multiple-limit="item.num"
                    @change="onCarIdChange($event, item.id)"
                    >
                  <el-option
                    v-for="item in carList"
                    :key="item.id"
                    :label="item.vin"
                    :value="item.id"></el-option>
                </el-select>
              </td>
            </tr>

          </table>
        </el-col>
      </el-row>

      <div slot="footer" class="dialog-footer" style="margin-top: 20px;">
        <el-button @click="bindCarVisible = false">关 闭</el-button>
        <!-- <el-button type="primary" @click.native.prevent="submitDoneSave">保存</el-button>
        <el-button type="primary" @click.native.prevent="submitDoneNext">{{isLastStep()?"完成":'提交下一步'}}</el-button> -->
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {validPhone} from '@/common/utils/validate.js'
import request from '@/common/utils/request.js'
import util from '../../../common/utils/util.js'
import {getToken} from '../../../common/utils/auth.js'
import {getTaskRecycleBinList, getTaskItemsAndLogsTid, getTaskInfo, updateItemCarIds,getTaskLookStepRecycle,getTaskItemsLogsRecycle } from '../../../api/test_order_task.js'
// import {getMyTaskList, taskSaveOrNext} from "../../../api/test_order.js";
// import {getAllTestCarEnterpriseList} from "../../../api/test_car_enterprise.js"
import {getTestCarListByEntId} from "../../../api/test_car.js"
// import {getAllCarTypeList} from '../../../api/car_type.js'
// import {getAllTestProductTypeList} from '../../../api/test_product_type.js'
// import {getAllTestGroupListByParam} from '../../../api/test_group.js'
// import {getAllTestSiteList} from '../../../api/test_site.js'
import {getAllUserList} from '../../../api/user.js'
// import {getAllTestOrgList} from '../../../api/test_org.js'

/*

*/

export default {
  name: "taskManage2",
  data() {
    return {
      total: 0,
      pageSize: 10,
      currentPage: 1,
      tableData: [],
      tableHeight: 200,
      taskLookStep:[],

      loadingDiv: null,
      searchForm: {
      },

      doneFormVisible:false,
      doneFormVisibles:false,
      doneForm:{
        tid:'',
        doneTaskItemIds:[],
        currentStep:'',
        next: 0,
      },
      taskItems:[],
      doneTaskItems:[],
      doneRow: '',

      backFormVisible:false,
      backForm:{
        tid:'',
        msg:'',
        currentStep:'',
        backStep:'',
      },
      backStepList:[],

      changeUserFormVisible:false,
      changeUserForm:{
        tid:'',
        msg:'',
        userId:'',
        currentStep:'',
      },

      userList: [],
      tOrderId: '',
      entId:'',
      carList:'',
      taskItemsAll:[],
      bindCarVisible: false,
    }
  },
  watch:{
    $route (to, from ) {
      // 监听路由变化, 实现类似 小程序的 onShow 事件
      if (to.path === '/task/test_order_manage') {
        if(this.nextShow){

        }
      }
    },

  },
  created() {

  },
  mounted() {

    let tOrderId = this.$route.params.tOrderId;
    this.tOrderId = tOrderId;
    this.entId = this.$route.params.entId;

    this.init();
    this.loadCarList();
    this.getDataList(this.currentPage);

    this.$nextTick(() => {
        this.tableHeight = document.documentElement.clientHeight - 198;
    })
    window.onresize = () => {
      this.$nextTick(() => {
          this.tableHeight = document.documentElement.clientHeight - 198;
      })
    }

    let t = getToken();
    this.uploadActionUrl = this.$adminApiUrl + "/file/upload?_t="+t;
    this.fileBaseUrl = this.$adminApiUrl+"/file/get?_t="+t+"&f=";
  },
  methods: {

    onCarIdChange(carIds, taskItemId){
      let title = "更新中"
      const loadingDiv = util.showLoading(title)
      updateItemCarIds({carIds: carIds, taskItemId: taskItemId}).then(res => {
        if(res.code == 0) {
          this.$alert(res.msg, "失败", {dangerouslyUseHTMLString:true,type:'warning'})
        }else if(res.code == 1) {
          this.$alert(res.msg, "成功", {dangerouslyUseHTMLString:true,type:'success'})
            .then(()=> {
              getTaskInfo({tid: row.tid}).then(res=>{
                if(res.code == 1){
                  this.taskItemsAll = res.data.testItems;
                }
              });
            })
        }
        loadingDiv.close();
      }).catch(res => {
        loadingDiv.close();
        this.$alert("绑定失败,请刷新后再试", "失败", {dangerouslyUseHTMLString:true,type:'warning'})
      })
    },

    loadCarList(){
      getTestCarListByEntId({carEnterpriseId: this.entId}).then(res=>{
        if(res.code == 1){
          this.carList = res.data;
        }
      });
    },

    handleBindCar(index,row){
      getTaskInfo({tid: row.tid}).then(res=>{
        if(res.code == 1){
          this.taskItemsAll = res.data.testItems;
          this.bindCarVisible = true;
        }
      });
    },
    lookStep(index, row){
      getTaskLookStepRecycle({tid: row.tOrderId}).then(res=>{
        // console.log(res)
        if(res.code == 1){
          this.taskLookStep = res.data;
          console.log(this.taskLookStep);
          this.doneForm.tid = row.tid;
          this.doneForm.currentStep = row.currentStep;
          this.doneRow = row;

          this.doneFormVisibles=true;
        }else{
          this.$message.error("加载信息失败")
        }
      });
    },

    handleShowTaskItems(index, row){
      // console.log(row);
      getTaskItemsLogsRecycle({tid: row.tid, step: row.currentStep}).then(res=>{
        // console.log(res)
        if(res.code == 1){
          this.taskItems = res.data.taskItems;
          this.doneTaskItems = res.data.doneTaskItems;

          let arr = [];
          if(!util.isEmpty(this.doneTaskItems)){
            for(let i in this.doneTaskItems){
              arr.push(this.doneTaskItems[i].orderTaskItemId)
            }
          }

          this.doneForm.doneTaskItemIds = arr;
          this.doneForm.tid = row.tid;
          this.doneForm.currentStep = row.currentStep;
          this.doneRow = row;

          this.doneFormVisible=true;
        }else{
          this.$message.error("加载信息失败")
        }
      });
    },

    handlePVTask(index, row){
      let item = {
        componentName:"testTaskPvManage",
        icon:"",
        path:"/task/test_task_pv_manage/"+row.tid,
        title: "子任务",
      };

      this.$store.commit("openTab",{item:item, router: (path)=>{this.$router.replace(path)}})

    },

    submitDoneSave(){
      this.doneForm.next = 0;
      this.submitDone();
    },

    submitDoneNext(){
      if(this.doneForm.doneTaskItemIds.length != this.taskItems.length){
        this.$message.error("请确认完成全部检测项目");
        return;
      }
      this.doneForm.next == 1;
      this.submitDone();
    },

    submitDone(){

      let title = "保存中"
      if(this.doneForm.next == 1){
        if(this.isLastStep()){
          title = "完成中"
        }else{
          title = "提交下一步中"
        }
      }

      const loadingDiv = util.showLoading(title)
      done(this.doneForm).then(res => {
        if(res.code == 0) {
          this.$alert(res.msg, "失败", {dangerouslyUseHTMLString:true,type:'warning'})
        }else if(res.code == 1) {
          this.$alert(res.msg, "成功", {dangerouslyUseHTMLString:true,type:'success'})
            .then(()=> {
              this.doneFormVisible=false;
              this.getDataList(this.currentPage)
            })
        }
        loadingDiv.close();
      }).catch(res => {
        loadingDiv.close();
      })
    },
    handleTaskDone(index, row){

      getTaskItemsAndLogsTid({tid: row.tid, step: row.currentStep}).then(res=>{
        console.log(res)
        if(res.code == 1){
          this.taskItems = res.data.taskItems;
          this.doneTaskItems = res.data.doneTaskItems;

          let arr = [];
          if(!util.isEmpty(this.doneTaskItems)){
            for(let i in this.doneTaskItems){
              arr.push(this.doneTaskItems[i].orderTaskItemId)
            }
          }
          this.doneForm.tid = row.tid;
          this.doneForm.currentStep = row.currentStep;
          this.doneRow = row;

          this.doneFormVisible=true;
        }else{
          this.$message.error("加载信息失败")
        }
      });


    },
    getDoneTitle(){
      if(util.isEmpty(this.doneForm.currentStep)){
        return "";
      }

      switch(this.doneForm.currentStep){
        case "a":
          return "检测方案核定";
        case "b":
          return "参数填报";
        case "c":
          return "方案参数审核";
        case "d":
          return "报告出具";
        case "e":
          return "报告审核";
        case "f":
          return "批准";
        case "g":
          return "原始记录";
        case "h":
          return "提交检测机构";
        case "i":
          return "检测机构已提交";
        case "j":
          return "检测报告生成";
        case "k":
          return "企业提交";
        case "l":
          return "反馈";
        case "m":
          return "反馈提交";
        case "n":
          return "审核通过";
        case "o":
          return "客户确认";

      }
    },

    getDoneTitles(data){
      switch(data){
        case "a":
          return "检测方案核定";
        case "b":
          return "参数填报";
        case "c":
          return "方案参数审核";
        case "d":
          return "报告出具";
        case "e":
          return "报告审核";
        case "f":
          return "批准";
        case "g":
          return "原始记录";
        case "h":
          return "提交检测机构";
        case "i":
          return "检测机构以已提交";
        case "j":
          return "检测报告生成";
        case "k":
          return "企业提交";
        case "l":
          return "反馈";
        case "m":
          return "反馈提交";
        case "n":
          return "审核通过";
        case "o":
          return "客户确认";

      }
    },

    isLastStep(){
      //公告：ABCDEF 1
      // 达标：ABDEFCGHI 2
      // CCC：ABFC 3
      // 环保：ABF 4
      // 其他：ABFJ 19
      if(this.doneRow.productTypeId1 == 1 && this.doneForm.currentStep == 'k'){
        return true;
      }
      if(this.doneRow.productTypeId1 == 2 && this.doneForm.currentStep == 'n'){
        return true;
      }
      if(this.doneRow.productTypeId1 == 3 && this.doneForm.currentStep == 'g'){
        return true;
      }
      if(this.doneRow.productTypeId1 == 4 && this.doneForm.currentStep == 'k'){
        return true;
      }
      if(this.doneRow.productTypeId1 == 19 && this.doneForm.currentStep == 'o'){
        return true;
      }

      return false;
    },

    handleTaskBack(index, row){
      this.backForm.tid = row.tid;
      this.backForm.msg = '';
      this.backForm.backStep = '';
      this.backForm.currentStep = row.currentStep;

      // 计算可以回退的步骤
      //公告：ABCDEF 1
      //达标：ABDEFCGHI 2
      //CCC：ABFC 3
      //环保：ABF 4
      //其他：ABFJ 19
      let steps = [];
      switch(row.productTypeId1){
        case 1:
          steps=['a','b','c','d','e','f','h','i','k'];
          break;
        case 2:
          steps=['a','b','c','d','e','f','g','h','j','k','l','m','n'];
          break;
        case 3:
          steps=['a','b','c','d','e','f','k','g'];
          break;
        case 4:
          steps=['a','b','c','d','e','f','k'];
          break;
        case 19:
          steps=['a','b','c','d','e','f','k','o'];
          break;
      }

      let arr = [];
      // let currentStep = 'e';
      let currentStep = this.backForm.currentStep;
      for(let i in steps){
        if(steps[i] == currentStep){
          break;
        }
        arr.push({
          "key": steps[i],
          "label": "工程师"+steps[i].toUpperCase(),
        });

        this.backStepList = arr;

      }

      this.backFormVisible = true;
    },
    submitBack(){
      if(util.isEmpty(this.backForm.backStep)){
        this.$message.error("请选择用户");
        return;
      }

      if(util.isEmpty(this.backForm.msg)){
        this.$message.error("请填写回退原因");
        return;
      }

      const loadingDiv = util.showLoading("回退中")
      back(this.backForm).then(res => {
        if(res.code == 0) {
          this.$alert(res.msg, "失败", {dangerouslyUseHTMLString:true,type:'warning'})
        }else if(res.code == 1) {
          this.$alert(res.msg, "成功", {dangerouslyUseHTMLString:true,type:'success'})
            .then(()=> {
              this.backFormVisible=false;
              this.getDataList(this.currentPage)
            })
        }
        loadingDiv.close();
      }).catch(res => {
        loadingDiv.close();
      })
    },

    handleTaskChangeUser(index, row){
      this.changeUserForm.tid = row.tid;
      this.changeUserForm.msg = '';
      this.changeUserForm.userId = '';
      this.changeUserForm.currentStep = row.currentStep;

      this.changeUserFormVisible = true;
    },
    submitChangeUser(){

      if(util.isEmpty(this.changeUserForm.userId)){
        this.$message.error("请选择用户");
        return;
      }

      const loadingDiv = util.showLoading("转交中")
      changeUser(this.changeUserForm).then(res => {
        if(res.code == 0) {
          this.$alert(res.msg, "失败", {dangerouslyUseHTMLString:true,type:'warning'})
        }else if(res.code == 1) {
          this.$alert(res.msg, "成功", {dangerouslyUseHTMLString:true,type:'success'})
            .then(()=> {
              this.changeUserFormVisible=false;
              this.getDataList(this.currentPage)
            })
        }
        loadingDiv.close();
      }).catch(res => {
        loadingDiv.close();
      })
    },
    init(){
    //   getAllTestCarEnterpriseList().then(res => {
    //     if(res.code == 1) {
    //       this.carEntList = res.data;
    //     }
    //   }).catch(res => {

    //   })
    //   this.getAllCarTypeList();

      // 获取所有检测产品类别
    //   getAllTestProductTypeList().then(res => {
    //     if(res.code == 1) {
    //       this.testProductTypeList = res.data;
    //     }
    //   }).catch(res => {

    //   });

      // 获取所有检测场地
    //   getAllTestSiteList().then(res => {
    //     if(res.code == 1) {
    //       this.testSiteList = res.data;
    //     }
    //   }).catch(res => {

    //   });

      // 获取所有用户列表
      getAllUserList().then(res => {
        if(res.code == 1) {
          this.userList = res.data;
        }
      }).catch(res => {

      });

    //   getAllTestOrgList().then(res => {
    //     if(res.code == 1) {
    //       this.orgList = res.data;
    //     }
    //   }).catch(res => {

    //   });

    },
    fmtDate(d2, fmt) { // yyyy-MM-dd hh:mm:ss
      if (util.isEmpty(d2) || d2 <= 0){
        return "";
      }
      return  util.fmtDate(new Date(d2), fmt);
    },
    significance(data){
      if(data==1){
        return "是";
      }else{
        return "否";
      }
    },
    submitForm() {
      this.editForm.next = 0;
      this.taskSaveOrNext();
    },
    submitFormNext() {
      this.editForm.next = 1;
      this.taskSaveOrNext();
    },

    getDataWithType(dataList, type){
      for(let i in dataList){
        if(dataList[i].type == type){
          return dataList[i];
        }
      }
    },

    taskSaveOrNext(){


      // this.$refs.editForm.validate(valid => {
        // if(valid) {
          this.loading = true;
          let loadingText = "暂存中...";
          if(this.editForm.next == 1){
            loadingText = "下一步中...";
            if(this.editForm.step==4){
              loadingText = "完成中...";
            }
          }
          const loadingDiv = util.showLoading(loadingText)
          taskSaveOrNext(this.editForm).then(res => {
            let title = "暂存"
            if(this.editForm.next == 1){
              title = "下一步"
              if(this.editForm.step==4){
                title = "完成"
              }
            }
            if(res.code == 0) {
              this.$alert(res.msg, title+"失败", {dangerouslyUseHTMLString:true,type:'warning'})
            }else if(res.code == 1) {
              this.$alert(res.msg, title+"成功", {dangerouslyUseHTMLString:true,type:'success'})
                .then(()=> {
                  this.editFormVisible=false;
                  this.getDataList(this.currentPage);
                  if(this.editForm.step==2){
                    this.step2EditFormVisible=false;
                  }else if(this.editForm.step==3){
                    this.step3EditFormVisible=false;
                  }else if(this.editForm.step==4){
                    this.step4EditFormVisible=false;
                  }
                })
            }
            this.loading = false;
            loadingDiv.close();
          }).catch(res => {
            this.loading = false;
            loadingDiv.close();
          })
        // }
      // });
    },

    handleDelete(index, row) {
      let loadingDiv;
      this.$confirm("是否确认删除?","删除确认").then(res=>{
        if(res='confirm'){
          loadingDiv = util.showLoading("删除中...")
          return deleteTestOrder({id: row.id})
        }
      }).then(res => {
        loadingDiv.close();
        if(res.code == 0) {
          this.$alert(res.msg, "删除失败", {dangerouslyUseHTMLString:true,type:'warning'})
        }else if(res.code == 1) {
          this.$alert(res.msg, "删除成功", {dangerouslyUseHTMLString:true,type:'success'})
            .then(res=>{
              this.editFormVisible=false;
              this.getDataList(this.currentPage);

            })
        }
      }).catch(res=>{
        if (loadingDiv){
          loadingDiv.close();
        }
      })
    },
    getDataList(pageNum){
      const loadingDiv = util.showLoading()

      let param = {};
      for(let key in this.searchForm){
        param[key] = this.searchForm[key];
      }
      param['pageSize'] = this.pageSize;
      param['pageNum'] = pageNum;
      param['tOrderId'] = this.tOrderId;

      getTaskRecycleBinList(param).then(res => {
        if(res.code == 0) {
          this.$message({
            showClose: true,
            message: res.msg,
            type: 'error'
          });
        }else if(res.code == 1) {
          let data = res.data;
          this.currentPage = pageNum;
          this.total = data.total;
          this.tableData = data.dataList;
        }
        loadingDiv.close();
      }).catch(res => {
        loadingDiv.close();
      })
    },
    search() {
      this.getDataList(this.currentPage)
    },
    handleSizeChange(pageSize) {
            this.pageSize = pageSize;
            this.getDataList(1)
          },
    handleCurrentChange(pageNum) {
            this.getDataList(pageNum);
          },
  }
}
</script>

<style scoped lang="scss">
  // @import "~@/common/styles/element-variables.scss";
  .search-box {
    background-color: #FFFFFF;
    min-height: 36px;
    line-height: 36px;
    padding-top: 2px;
    padding-bottom: 6px;
    .el-form-item {
      margin-bottom: 0px !important;
    }
    .el-form--inline {
      display: inline-block;
    }
  }
  .pagination-box {
    text-align: left;
    margin-top: 10px;
  }
  .test-item-table{
    width: 80%;
    border-collapse: collapse;

    th, td {
      width: 33.3%;
      text-align: center;
      border: 1px solid #CCC;
    }
  }

  .test-item-table{
    width: 100%;
    border-collapse: collapse;
    tr{
      height: 40px;
    }

    th, td {
      width: 3%;
      text-align: center;
      border: 1px solid #CCC;
    }
    th {
      background-color: #EDF2FC;
    }
  }
</style>
<style lang="scss">
  .el-dialog__header {

  }
  .el-dialog__body {
    padding-top: 10px;
    padding-bottom: 0px;
  }
  .el-dialog__footer {
    padding-top: 0px;
  }
</style>
